package com.yf1706.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.yf1706.bean.Multiselect;
import com.yf1706.bean.QuestionBank;
import com.yf1706.bean.SingleChoice;
import com.yf1706.dao.jpa.multiSelectJDAO;
import com.yf1706.dao.jpa.questionBankJDAO;
import com.yf1706.dao.mybatis.multiselectMDAO;

@Service
public class multiSelectService {
	@Autowired
	private multiselectMDAO mltdao;

	@Autowired
	private multiSelectJDAO msjdao;

	@Autowired
	private questionBankJDAO qbjdao;

	/* 查询所有多选题 */
	public List<Multiselect> getMultiselect() {
		return mltdao.queryMultiselect();
	}

	/* 通过题库查到多选表中此题库所有的题 */
	public List<Multiselect> findByQuestionBank(QuestionBank q) {
		return msjdao.findByQuestionBank(q);
	}

	/* 根据题库id查询多选表中所有此题库的题目 */
	public List<Multiselect> querybyQbId(int qbId) {
		return mltdao.querybyQbId(qbId);
	}

	// 在题库添加题目
	public void questionbankAddMultiSelect(String answer, String a, String b, String c, String d,
			String examQuestion, String qbId, String createPeople) {
		Multiselect sc = new Multiselect();
		sc.setA(a);
		sc.setAnswer(answer);
		sc.setB(b);
		sc.setC(c);
		sc.setD(d);
		sc.setCreatePeople(createPeople);
		sc.setCreateDate(new Date());
		sc.setExamQuestion(examQuestion);
		int qbid = Integer.parseInt(qbId);
		sc.setQuestionBank(qbjdao.findByQbId(qbid));
		msjdao.save(sc);
	}

	public void deleteQuestionBankMultiSelect(int multiSelectId) {
		// TODO Auto-generated method stub
		msjdao.deleteById(multiSelectId);
	}

	public List<Multiselect> queryAllByQbIdAndExamQuestion(int qbId, String string) {

		return mltdao.queryAllByQbIdAndExamQuestion(qbId, string);
	}

	public List<Multiselect> findByMultiSelectId(int multiselectId) {

		return msjdao.findByMultiselectId(multiselectId);
	}

	public void deletMultiselectById(int multiselectId) {
		msjdao.deleteById(multiselectId);

	}

	
}
